﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Entity;
using BUS;
namespace CustomerManager
{
    public partial class ucLogin : UserControl
    {
        FrmMain frm;
        public ucLogin()
        {
            InitializeComponent();
        }

        public void ClearAll()
        {
            txtPassword.Clear();
            txtUsername.Clear();
        }

        private void btnLogin_Click(object sender, EventArgs e)
        {
            try
            {
                NhanVien nv = NhanVienBUS.DangNhap(txtUsername.Text, txtPassword.Text);
                if (nv == null)
                {
                    MessageBox.Show("Đăng nhập thất bại");
                }
                else
                {
                    ClearAll();
                    frm.LogedIn(true);
                    if (nv.ChucVu == "NV")
                        frm.status = nv.MaNV;
                    else
                        frm.status = -1;
                    frm.loadcustomer();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void ucLogin_Load(object sender, EventArgs e)
        {
        }

        public void loadfrmmain()
        {
            frm = (FrmMain)Application.OpenForms["FrmMain"];
        }
    }
}
